home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <GL/glx.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <stdio.h>
-
- static long W = 300, H = 300;
- static int attributeList[] = {GLX_RGBA, None};
- static Bool WaitForNotify (Display *d, XEvent *e, char *arg)
- {
- return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
- }
- static GLUquadricObj *qobj;
-
- void gldrawing(void)
- {
- glLoadIdentity();
- glOrtho(-500.0, 500.0, -500.0, 500.0, -500.0, 500.0);
- glClearColor(0.0, 0.0, 0.0, 0.0);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glColor3f(0.8, 0.4, 0.8);
- glLineWidth(2.0);
-
- glPushMatrix();
- glRotatef(20.0, 1,1,0);
- gluQuadricDrawStyle(qobj, GLU_LINE);
- gluSphere(qobj, 250.0, 25, 20);
- glPopMatrix();
-
- glFlush();
- }
-
- main(int argc, char **argv)
- {
- Display *dpy; /* X Display */
- XColor acolor; /* Color definitions */
- XVisualInfo *vi; /* X Visual */
- Colormap cmap; /* X Colormap */
- XSetWindowAttributes swa; /* X Window Attributes */
- Window win; /* X Window Id */
- GLXContext cx; /* Extesion to X server; GLX context
- Data structure for X to hold GL global
- data, so that we don't have to send them
- to X through protocal everytime to
- eliminate X traffic */
- XEvent event, report; /* X event */
- int value;
-
- /* Standard code to open a X window */
- dpy = XOpenDisplay (0);
- XSynchronize(dpy, True);
- /* get a appropriate visual */
- vi = glXChooseVisual (dpy, DefaultScreen(dpy), attributeList);
-
- /* create a GLX context */
- cx = glXCreateContext (dpy, vi, None, GL_FALSE);
-
- /* create a colormap using this visual */
- cmap = XCreateColormap (dpy, RootWindow(dpy, vi->screen), vi->visual,
- AllocNone);
-
- /* create a X Window */
- swa.colormap = cmap;
- swa.border_pixel = 0;
- swa.event_mask = StructureNotifyMask | KeyPressMask;
- win = XCreateWindow (dpy, RootWindow(dpy,vi->screen), 0, 0, 500, 500,
- 0, vi->depth, InputOutput, vi->visual,
- CWBorderPixel|CWColormap|CWEventMask, &swa);
-
- XSelectInput(dpy, win, ExposureMask | KeyPressMask |
- ButtonPressMask | StructureNotifyMask);
- XMapWindow (dpy,win);
- /* wait for window to map */
- XIfEvent (dpy, &event,WaitForNotify, (char *)win);
-
- /* connect the context to the window */
- if (!glXMakeCurrent(dpy,win,cx) == GL_TRUE) {
- return 0;
- }
-
- qobj = gluNewQuadric();
- while (1) {
- XNextEvent(dpy, &report);
- switch (report.type) {
- case KeyPress:
- gluDeleteQuadric(qobj);
- XCloseDisplay(dpy);
- exit(1);
- break;
- case Expose:
- gldrawing();
- break;
- default:
- break;
- } /*end switch*/
- } /*end while*/
- }
-
-